﻿
Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Partial Class transcompletelist
    Inherits System.Web.UI.Page

#Region " Properties "

    Public Property CurrentPage() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPage As Object = ViewState("_CurrentPage")
            If objPage Is Nothing Then
                Return 0
            Else
                'default to showing the first page
                Return CInt(objPage)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property

    Public Property PageSize() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPageSize As Object = ViewState("_PageSize")
            If objPageSize Is Nothing Then
                Return 25
            Else
                'default to showing the first page
                Return CInt(objPageSize)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_PageSize") = value
        End Set
    End Property

#End Region

#Region " Paging and Page Size "

    Protected Sub lnkHead10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead10Item.Click
        PageSize = 10
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkHead25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead25Item.Click
        PageSize = 25
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkHead100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead100Item.Click
        PageSize = 100
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkHead150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead150Item.Click
        PageSize = 150
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot10Item.Click
        PageSize = 10
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot25Item.Click
        PageSize = 25
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot100Item.Click
        PageSize = 100
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot150Item.Click
        PageSize = 150
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub btnMoveFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        CurrentPage = 0
        txtPageNo.Text = CurrentPage + 1
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If CurrentPage > 0 Then
            CurrentPage = CurrentPage - 1
            txtPageNo.Text = CurrentPage + 1
            btnSearch_Click(sender, e)
        End If
    End Sub

    Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If CInt(txtPageNo.Text < 1) Then
            txtPageNo.Text = 1
        End If

        If CInt(txtPageNo.Text > CInt(lblMaxPageCount.Text)) Then
            txtPageNo.Text = CInt(lblMaxPageCount.Text) + 1
        End If

        CurrentPage = CInt(txtPageNo.Text) - 1
        btnSearch_Click(sender, e)

    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If CurrentPage < CInt(lblMaxPageCount.Text) Then
            CurrentPage = CurrentPage + 1
            txtPageNo.Text = CurrentPage + 1
            btnSearch_Click(sender, e)
        End If
    End Sub

    Protected Sub btnMoveLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        CurrentPage = CInt(lblMaxPageCount.Text)
        txtPageNo.Text = CurrentPage + 1
        btnSearch_Click(sender, e)
    End Sub

#End Region

    Dim sum, grossamount As Decimal

    Private Sub LoadPropertyType(Optional ByVal Type As String = "")

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        If Type = "" Then
            objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType ORDER BY Type"
        Else
            objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType WHERE Type LIKE @Type ORDER BY Type"
            objDB.AddParameter("Type", Data.SqlDbType.NVarChar, "%" & Type & "%")
        End If
        objDB.FillData(TempDT, "PropertyType", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        repPropertyType.DataSource = TempDT
        repPropertyType.DataBind()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        ElseIf Session.Item("StaffType").ToString = "2" Then
            lnkGross.Visible = False
        End If

        'Edited by minginn @ 27/6/2011 - to load the same search when user back from other page
        If Not Session("Back") Is Nothing Then
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            '0-Back Page
            '1-Project
            '2-Road Name
            '3-Unit Number
            '4-Property Type
            '5-Location Name
            '6-List Type
            '7-Page Size
            '8-Current Page
            If arr(0).ToString.Contains("transcompletelist.aspx") Then
                txtProject.Text = arr(1).ToString
                txtRoadName.Text = arr(2).ToString
                txtUnitNumber.Text = arr(3).ToString
                txtPropertyType.Text = arr(4).ToString
                txtLocationName.Text = arr(5).ToString
                ddlListType.SelectedValue = arr(6).ToString
                PageSize = CInt(arr(7).ToString)
                CurrentPage = CInt(arr(8).ToString)
                Session.Remove("Back")
                SearchCompleteList()
            Else
                Session.Remove("Back")
            End If
           
        End If

        If Not Session("Reminder") Is Nothing Then
            SearchReminderCompleteList()
        End If

        If Not Session("PropertyAt") Is Nothing Then
            If Session("PropertyAt") = "NFSR" Then
                lblTitle.Text = "NFS/SBO/NFR/SBL"
            End If
        End If

        If Not Page.IsPostBack Then

            lblUserID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

            If Not Session.Item("entry") Is Nothing Then
                lblMsgSuccessful.Text = "<strong>Information:</strong>Staff <strong>" & Session.Item("entry").ToString & "</strong> transaction was updated"
                divSuccessful.Visible = True
                Session.Remove("entry")
            End If

        End If

    End Sub

    Protected Sub btnSearchPropertyType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchPropertyType.Click
        If txtPropertyType.Text = "" Then
            LoadPropertyType()
        Else
            LoadPropertyType(txtPropertyType.Text)
        End If
        mpePropertyTypeEntry.Show()
    End Sub

    Protected Sub repPropertyType_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repPropertyType.ItemCommand

        If e.CommandName = "SelectType" Then
            Dim PropertyType As String = CType(repPropertyType.Items(e.CommandArgument).FindControl("lnkRepPropertyType"), LinkButton).Text
            txtPropertyType.Text = PropertyType
        End If
    End Sub

    Protected Sub btnResetSearchFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnResetSearchFilter.Click
        txtProject.Text = String.Empty
        txtRoadName.Text = String.Empty
        txtLocationName.Text = String.Empty
        txtUnitNumber.Text = String.Empty
        txtPropertyType.Text = String.Empty
    End Sub

    Private Sub SearchReminderCompleteList()
        sum = 0
        grossamount = 0

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim PropertyDT As New Data.DataTable
        'Edited By minginn @ 30/9/2011 - Use Initial instead of name
        objDB.dbVariable.SQLString = "SELECT AW_Property.PropertyId ,AW_Property.UnitNumber,AW_Road.Road, AW_Location.Location,AW_State.State, AW_Country.Country, " & _
                            "AW_Project.Project, AW_Project.ProjectDesc,AW_PropertyType.Type, AW_PropertyType.TypeDesc, " & _
                            "AW_RentTransaction.TransactionId as TransactionId,AW_RentTransaction.TransactDate,AW_RentTransaction.Status, " & _
                            "AW_RentTransaction.TransactorId, AW_Staff.Name, AW_Staff.Initial " & _
                            "FROM AW_Property " & _
                            "INNER JOIN AW_RentTransaction ON AW_Property.PropertyId = AW_RentTransaction.PropertyId " & _
                            "LEFT OUTER JOIN AW_Road ON AW_Property.RoadId=AW_Road.RoadId " & _
                            "LEFT OUTER JOIN AW_Location ON AW_Road.LocationId=AW_Location.LocationId " & _
                            "LEFT OUTER JOIN AW_State ON AW_Location.StateId=AW_State.StateId " & _
                            "LEFT OUTER JOIN AW_Country ON AW_State.CountryId=AW_Country.CountryId " & _
                            "LEFT OUTER JOIN AW_Project ON AW_Property.ProjectId=AW_Project.ProjectId " & _
                            "LEFT OUTER JOIN AW_PropertyType ON AW_Property.PropertyTypeId=AW_PropertyType.TypeId " & _
                            "LEFT OUTER JOIN AW_Staff ON AW_RentTransaction.TransactorId=AW_Staff.StaffId " & _
                            "WHERE AW_RentTransaction.TransactionId=@TransactionId"
        objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(Session("Reminder").ToString))
        Session.Remove("Reminder")
        objDB.FillData(PropertyDT, "Property", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        'Creating a Paged Datasouce
        Dim objPaged As New PagedDataSource
        Dim FilterString As String = String.Empty
        Dim FilteredProperty As New Data.DataView(PropertyDT)

        'FilteredProperty.Sort = lblhidSortType.Text
        objPaged.DataSource = FilteredProperty
        objPaged.AllowPaging = True
        objPaged.PageSize = PageSize
        objPaged.CurrentPageIndex = CurrentPage

        lblHeadNoOfItem.Text = PropertyDT.Rows.Count
        lblFootNoOfItem.Text = PropertyDT.Rows.Count

        repProperty.DataSource = objPaged
        repProperty.DataBind()

        lblMaxPageCount.Text = objPaged.PageCount - 1
        lblTotalPage.Text = " of " & objPaged.PageCount
    End Sub

    Private Sub SearchCompleteList()

        Dim strWhere As String = ""
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))

        If txtProject.Text.Trim <> "" Then
            strWhere = strWhere & " AND AW_Project.Project LIKE @Project "
            objDB.AddParameter("Project", Data.SqlDbType.NVarChar, "%" & txtProject.Text.Trim & "%")
        End If

        If txtRoadName.Text <> "" Then
            strWhere = strWhere & " AND AW_Road.Road LIKE @Road "
            objDB.AddParameter("Road", Data.SqlDbType.NVarChar, "%" & txtRoadName.Text.Trim & "%")
        End If

        If txtLocationName.Text <> "" Then
            strWhere = strWhere & " AND AW_Location.Location LIKE @Location "
            objDB.AddParameter("Location", Data.SqlDbType.NVarChar, "%" & txtLocationName.Text.Trim & "%")
        End If

        If txtUnitNumber.Text <> "" Then
            strWhere = strWhere & " AND AW_Property.UnitNumber LIKE @UnitNo "
            objDB.AddParameter("UnitNo", Data.SqlDbType.NVarChar, "%" & txtUnitNumber.Text.Trim & "%")
        End If

        If txtPropertyType.Text <> "" Then
            strWhere = strWhere & " AND AW_PropertyType.Type LIKE @Type "
            objDB.AddParameter("Type", Data.SqlDbType.NVarChar, "%" & txtPropertyType.Text.Trim & "%")
        End If

        'Edited by Tan Chin Teong @20121028 - to add in NFS/NFR/SBO/RBL 
        If Session("PropertyAt") = "NFSR" Then
            objDB.AddParameter("TransStatus", Data.SqlDbType.Int, 6) ' 6 - NFSR
        Else
            objDB.AddParameter("TransStatus", Data.SqlDbType.Int, 3) ' 3 - COMPLETED
        End If

        objDB.OpenConnection()

        If ddlListType.SelectedValue = "0" Then
            'Edited By minginn @ 30/9/2011 - Use Initial instead of name
            'Added by : Daniel Lee
            'Date : 24-Aug-2011
            'To include undo date AW_SalesTranaction.UndoDate to check if the transaction is being aborted if yes then hide the renew.
            lblCurrentTransType.Text = "S"

            If lblStaffType.Text = "2" Then
                strWhere = strWhere & " AND (AW_SaleTransaction.TransactorId=@UserId OR AW_SaleTransaction.ListerId=@UserId) "
                objDB.AddParameter("UserId", Data.SqlDbType.UniqueIdentifier, New Guid(lblUserID.Text.Trim))
            End If

            objDB.dbVariable.SQLString = "SELECT AW_Property.PropertyId ,AW_Property.UnitNumber,AW_Road.Road, AW_Location.Location,AW_State.State, AW_Country.Country, " & _
                             "AW_Project.Project, AW_Project.ProjectDesc,AW_Project.Picture,AW_PropertyType.Type, AW_PropertyType.TypeDesc, " & _
                             "AW_SaleTransaction.TransactionId AS TransactionId,AW_SaleTransaction.TransactDate,AW_SaleTransaction.Status,AW_SaleTransaction.GrossAmount, " & _
                             "AW_SaleTransaction.TransactorId, AW_Staff.Name, AW_Staff.Initial, AW_SaleTransaction.UndoDate " & _
                             "FROM AW_Property " & _
                             "INNER JOIN AW_SaleTransaction ON AW_Property.PropertyId = AW_SaleTransaction.PropertyId " & _
                             "LEFT OUTER JOIN AW_Road ON AW_Property.RoadId=AW_Road.RoadId " & _
                             "LEFT OUTER JOIN AW_Location ON AW_Road.LocationId=AW_Location.LocationId " & _
                             "LEFT OUTER JOIN AW_State ON AW_Location.StateId=AW_State.StateId " & _
                             "LEFT OUTER JOIN AW_Country ON AW_State.CountryId=AW_Country.CountryId " & _
                             "LEFT OUTER JOIN AW_Project ON AW_Property.ProjectId=AW_Project.ProjectId " & _
                             "LEFT OUTER JOIN AW_PropertyType ON AW_Property.PropertyTypeId=AW_PropertyType.TypeId " & _
                             "LEFT OUTER JOIN AW_Staff ON AW_SaleTransaction.TransactorId=AW_Staff.StaffId " & _
                             "WHERE AW_SaleTransaction.Status = @TransStatus " & _
                             strWhere & lblhidSortType.Text
        Else
            'Added by : Daniel Lee
            'Date : 24-Aug-2011
            'To include undo date AW_RentTransaction.UndoDate to check if the transaction is being aborted if yes then hide the renew.
            lblCurrentTransType.Text = "R"

            If lblStaffType.Text = "2" Then
                strWhere = strWhere & " AND (AW_RentTransaction.TransactorId=@UserId OR AW_RentTransaction.ListerId=@UserId) "
                objDB.AddParameter("UserId", Data.SqlDbType.UniqueIdentifier, New Guid(lblUserID.Text.Trim))
            End If

            objDB.dbVariable.SQLString = "SELECT AW_Property.PropertyId ,AW_Property.UnitNumber,AW_Road.Road, AW_Location.Location,AW_State.State, AW_Country.Country, " & _
                             "AW_Project.Project, AW_Project.ProjectDesc,AW_Project.Picture,AW_PropertyType.Type, AW_PropertyType.TypeDesc, " & _
                             "AW_RentTransaction.TransactionId as TransactionId,AW_RentTransaction.TransactDate,AW_RentTransaction.Status,AW_RentTransaction.GrossAmount, " & _
                             "AW_RentTransaction.TransactorId, AW_Staff.Name, AW_Staff.Initial, AW_RentTransaction.UndoDate " & _
                             "FROM AW_Property " & _
                             "INNER JOIN AW_RentTransaction ON AW_Property.PropertyId = AW_RentTransaction.PropertyId " & _
                             "LEFT OUTER JOIN AW_Road ON AW_Property.RoadId=AW_Road.RoadId " & _
                             "LEFT OUTER JOIN AW_Location ON AW_Road.LocationId=AW_Location.LocationId " & _
                             "LEFT OUTER JOIN AW_State ON AW_Location.StateId=AW_State.StateId " & _
                             "LEFT OUTER JOIN AW_Country ON AW_State.CountryId=AW_Country.CountryId " & _
                             "LEFT OUTER JOIN AW_Project ON AW_Property.ProjectId=AW_Project.ProjectId " & _
                             "LEFT OUTER JOIN AW_PropertyType ON AW_Property.PropertyTypeId=AW_PropertyType.TypeId " & _
                             "LEFT OUTER JOIN AW_Staff ON AW_RentTransaction.TransactorId=AW_Staff.StaffId " & _
                             "WHERE AW_RentTransaction.Status = @TransStatus " & _
                             strWhere & lblhidSortType.Text

        End If
        Dim PropertyDT As New Data.DataTable
        objDB.FillData(PropertyDT, "Property", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        'Creating a Paged Datasouce
        Dim objPaged As New PagedDataSource
        Dim FilterString As String = String.Empty
        Dim FilteredProperty As New Data.DataView(PropertyDT)

        'FilteredProperty.Sort = lblhidSortType.Text
        objPaged.DataSource = FilteredProperty
        objPaged.AllowPaging = True
        objPaged.PageSize = PageSize
        objPaged.CurrentPageIndex = CurrentPage

        lblHeadNoOfItem.Text = PropertyDT.Rows.Count
        lblFootNoOfItem.Text = PropertyDT.Rows.Count

        repProperty.DataSource = objPaged
        repProperty.DataBind()

        lblMaxPageCount.Text = objPaged.PageCount - 1
        lblTotalPage.Text = " of " & objPaged.PageCount

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        SearchCompleteList()

    End Sub

    Protected Sub repProperty_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repProperty.ItemCommand
        'Edited by minginn - To allow user to go back to the search page with same search selection
        'Back Page
        'Project
        'Road Name
        'Unit Number
        'Property Type
        'Location Name
        'List Type
        'Page Size
        'Current Page
        Dim strBack As String
        strBack = "transcompletelist.aspx" & "ڡ" & txtProject.Text.Trim & "ڡ" & txtRoadName.Text.Trim & "ڡ" & _
                txtUnitNumber.Text.Trim & "ڡ" & txtPropertyType.Text.Trim & "ڡ" & txtLocationName.Text.Trim & "ڡ" & _
                ddlListType.SelectedValue & "ڡ" & PageSize & "ڡ" & CurrentPage
        Session.Add("Back", strBack)
        If e.CommandName = "ViewTrans" Then
            If lblCurrentTransType.Text = "S" Then
                'Sales
                Dim TransactionID As Guid = New Guid(e.CommandArgument.ToString)
                Session.Add("Tid", TransactionID.ToString)
                Response.Redirect("stransview.aspx", False)
            Else
                'Rent
                Dim TransactionID As Guid = New Guid(e.CommandArgument.ToString)
                Session.Add("Tid", TransactionID.ToString)
                Response.Redirect("rtransview.aspx", False)
            End If
        ElseIf e.CommandName = "ReList" Then
            ReList(e.CommandArgument.ToString)
        ElseIf e.CommandName = "ReNew" Then
            Session.Add("tid", e.CommandArgument.ToString)
            Response.Redirect("renew.aspx", True)
        ElseIf e.CommandName = "Compare" Then
            If lblCurrentTransType.Text = "S" Then
                Response.Redirect("stranscompare.aspx?id=" & SymmetricEncryptToHex(e.CommandArgument, "augment"))
            Else
                Response.Redirect("rtranscompare.aspx?id=" & SymmetricEncryptToHex(e.CommandArgument, "augment"))
            End If
        End If
    End Sub

    Protected Sub repProperty_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repProperty.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            CType(e.Item.FindControl("lblRepProjectType"), LinkButton).Attributes.Add("onmouseover", "return overlib('" & CType(e.Item.FindControl("lblRepTypeDesc"), Label).Text & "',ABOVE);")

            If CType(e.Item.FindControl("lblRepProject"), LinkButton).Text <> "" Then
                If CType(e.Item.FindControl("lblRepProjectPIcture"), Label).Text <> "" Then
                    CType(e.Item.FindControl("lblRepProject"), LinkButton).Attributes.Add("onmouseover", "return overlib('" & CType(e.Item.FindControl("lblRepProjectDesc"), Label).Text & "<hr /><img alt=""picture"" width=""100px"" height=""100px"" src=""project/" & CType(e.Item.FindControl("lblRepProjectPIcture"), Label).Text & """/>',ABOVE);")
                Else
                    CType(e.Item.FindControl("lblRepProject"), LinkButton).Attributes.Add("onmouseover", "return overlib('" & CType(e.Item.FindControl("lblRepProjectDesc"), Label).Text & "',ABOVE);")
                End If

            End If

            If CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "4" Then
                CType(e.Item.FindControl("imgbutRelist"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutReNew"), ImageButton).Visible = False
            End If

            If CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "5" Then
                CType(e.Item.FindControl("imgbutReNew"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutRelist"), ImageButton).Visible = False
            End If

            If lblCurrentTransType.Text = "S" Then
                CType(e.Item.FindControl("imgbutReNew"), ImageButton).Visible = False
            End If

            If Session("PropertyAt") = "NFSR" Then
                CType(e.Item.FindControl("imgbutViewTrans"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutReNew"), ImageButton).Visible = False
            End If

            Dim strAddress As String = CType(e.Item.FindControl("lblRepUnitNumber"), Label).Text & ", " & CType(e.Item.FindControl("lblRepRoad"), LinkButton).Text & ", " & CType(e.Item.FindControl("lblRepLocation"), LinkButton).Text & ", " & CType(e.Item.FindControl("lblRepState"), LinkButton).Text & ", " & CType(e.Item.FindControl("lblRepCountry"), LinkButton).Text

            If CType(e.Item.FindControl("lblRepProject"), LinkButton).Text <> "" Then
                strAddress = strAddress & vbCrLf & "(" & CType(e.Item.FindControl("lblRepProject"), LinkButton).Text & ")"
            End If

            CType(e.Item.FindControl("cbeReList"), Object).ConfirmText = "Are you sure you want to RELIST this PROPERTY?" & vbCrLf & vbCrLf & strAddress

            CType(e.Item.FindControl("cbeReNew"), Object).ConfirmText = "Are you sure you want to RENEW this PROPERTY?" & vbCrLf & vbCrLf & strAddress

            Select Case CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text
                Case "1"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "PENDING SIGNING"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "2"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "PENDING COLLECTION"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "3"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "COMPLETED"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "0"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "NEW"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "4"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "RELIST"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "5"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "RENEW"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "6"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "NFS/NFR/SBO/RBL"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
            End Select

            If CType(e.Item.FindControl("lblHideAbort"), Label).Text <> "" Then
                CType(e.Item.FindControl("imgbutReNew"), ImageButton).Visible = False
                CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "COMPLETED(ABORT)"
            End If

            If Session.Item("StaffType").ToString = "2" Then
                CType(e.Item.FindControl("imgbutViewTrans"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutRelist"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutReNew"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutCompare"), ImageButton).Visible = False
                CType(e.Item.FindControl("lblGross"), LinkButton).Visible = False
                'lnkGross.Visible = False
            Else
                If Not IsDBNull(DataBinder.Eval(e.Item.DataItem, "GrossAmount")) Then
                    grossamount = CDbl(DataBinder.Eval(e.Item.DataItem, "GrossAmount"))
                Else
                    grossamount = 0
                End If
                sum += CDbl(grossamount)
            End If

           

        ElseIf e.Item.ItemType = ListItemType.Footer Then
            If Session.Item("StaffType").ToString = "2" Then
                CType(e.Item.FindControl("lblItemCount"), Label).Visible = False
                CType(e.Item.FindControl("lbltotal"), Label).Visible = False
            Else
                CType(e.Item.FindControl("lblItemCount"), Label).Text = String.Format("{0:#,##0.00}", sum)
            End If
        End If
    End Sub

    Private Sub ReList(ByVal TransactionID As String)

        '1. Check if any rent transaction is at status 1
        '2. If yes prompt message disallow relist
        '3. Begin perform relist operation, Delete owner/Landlord and all price information.
        '4. SET Rrelist NULL and SReslit to NULL, Remove the SCreateDate
        '5. Remove sTrnasactionID and rTransactionId
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim PropertyId As String = ""
        Dim TransactionDT As New Data.DataTable

        objDB.OpenConnection()
        If lblCurrentTransType.Text = "S" Then        'Relist Sales Property  
            objDB.dbVariable.SQLString = "SELECT PropertyId FROM AW_SaleTransaction WHERE TransactionId=@TransactionId"
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionID))
            objDB.FillData(TransactionDT, "Transaction", Database.SQLCommandType.NormalString)

            For Each ReadRow As Data.DataRow In TransactionDT.Rows
                PropertyId = ReadRow.Item("PropertyId").ToString
            Next

            Dim CheckRentTransaction As New Data.DataTable
            Dim RRelistStatus As String = ""
            Dim RTransactionId As String = ""

            'Check if Rent Transaction is at sttus 1
            objDB.dbVariable.SQLString = "SELECT RRelistStatus, RTransactionId FROM AW_Property WHERE PropertyId=@PropertyId"
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
            objDB.FillData(CheckRentTransaction, "RentTrans", Database.SQLCommandType.NormalString)

            For Each ReadRow As Data.DataRow In CheckRentTransaction.Rows
                RRelistStatus = ReadRow.Item("RRelistStatus").ToString
                RTransactionId = ReadRow.Item("RTransactionId").ToString
            Next

            If RRelistStatus = "1" Then
                divError.Visible = True
                lblMsgError.Text = "There is a pending RENT transaction. Please either COMPLETE the trasaction or ABORT the transaction"
                Exit Sub
            Else
                'begin relist
                Try
                    objDB.InitDbTrans()
                    objDB.dbVariable.SQLString = "UPDATE AW_Property SET ListType=@ListType," & _
                                                 "RRelistStatus=@RListStatus,SRelistStatus=@SListStatus,RTransactionId=@RTransactionId,STransactionId=@STransactionId,UpdateDate=@UpdateDate,UpdateWho=@UpdateWho, " & _
                                                 "SListerId=@SListerId, RListerId=@RlisterId, CreateDate=@CreateDate,SCreateDate=@SCreateDate,RCreateDate=@RCreateDate, " & _
                                                 "SRAmt=@SRAmt,SRPSF=@SRPSF,SRAskAmt=@SRAskAmt,SRAskPSF=@SRAskPSF,SRCreateDate=@SRCreateDate,SRYes=@SRYes, " & _
                                                 "SCAmt=@SCAmt,SCPSF=@SCPSF,SCAskAmt=@SCAskAmt,SCAskPSF=@SCAskPSF,SCCreateDate=@SCCreateDate,SCYes=@SCYes, " & _
                                                 "SLAmt=@SLAmt,SLPSF=@SLPSF,SLAskAmt=@SLAskAmt,SLAskPSF=@SLAskPSF,SLCreateDate=@SLCreateDate,SLYes=@SLYes, " & _
                                                 "SIAmt=@SIAmt,SIPSF=@SIPSF,SIAskAmt=@SIAskAmt,SIAskPSF=@SIAskPSF,SICreateDate=@SICreateDate,SIYes=@SIYes, " & _
                                                 "RRAmt=@RRAmt,RRPSF=@RRPSF,RRAskAmt=@RRAskAmt,RRAskPSF=@RRAskPSF,RRCreateDate=@RRCreateDate,RRYes=@RRYes, " & _
                                                 "RCAmt=@RCAmt,RCPSF=@RCPSF,RCAskAmt=@RCAskAmt,RCAskPSF=@RCAskPSF,RCCreateDate=@RCCreateDate,RCYes=@RCYes, " & _
                                                 "RLAmt=@RLAmt,RLPSF=@RLPSF,RLAskAmt=@RLAskAmt,RLAskPSF=@RLAskPSF,RLCreateDate=@RLCreateDate,RLYes=@RLYes, " & _
                                                 "RIAmt=@RIAmt,RIPSF=@RIPSF,RIAskAmt=@RIAskAmt,RIAskPSF=@RIAskPSF,RICreateDate=@RICreateDate,RIYes=@RIYes  " & _
                                                 "WHERE PropertyId=@PropertyId"
                    '"OwnerName=@OwnerName, OwnerMobile=@OwnerMobile,OwnerPhone=@OwnerPhone,OwnerFax=@OwnerFax,OwnerEmail=@OwnerEmail,OwnerAddress=@OwnerAddress, " & _
                    '"LandlordName=@LandlordName,LandlordMobile=@LandlordMobile,LandlordPhone=@LandlordPhone,LandlordFax=@LandlordFax,LandlordEmail=@LandlordEmail,LandlordAddress=@LandlordAddress, " & _

                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("OwnerName", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerFax", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
                    objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("STransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("SRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, DBNull.Value)   'Edited by tanchinteong @26112012 -> @06012013
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.ExecuteQuery()

                    objDB.dbVariable.SQLString = "UPDATE AW_SaleTransaction SET Status=4 WHERE TransactionId=@TransactionId"
                    objDB.ClearParameter()
                    objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionID))
                    objDB.ExecuteQuery()

                    If (RRelistStatus <> "" And RTransactionId <> "") Then
                        objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET Status=4 WHERE TransactionId=@TransactionId"
                        objDB.ClearParameter()
                        objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(RTransactionId))
                        objDB.ExecuteQuery()
                        InsertTrans_Old(TransactionID, RTransactionId, objDB)
                        divSuccessful.Visible = True
                        lblMsgSuccessful.Text = "Both SALES and RENT has been RELISTED"
                    Else
                        InsertTrans_Old(TransactionID, "", objDB)
                        divSuccessful.Visible = True
                        lblMsgSuccessful.Text = "SALES has been RELISTED"
                    End If
                    objDB.DbTransCommit()
                    objDB.CloseConnection()

                    SearchCompleteList()
                Catch ex As Exception
                    objDB.DbTransRollback()
                    objDB.CloseConnection()
                    lblMsgError.Text = "There is an error with the following error message : " & ex.Message
                    divError.Visible = True

                End Try
                Exit Sub
            End If

        Else    'Relist Rent Property  
            objDB.dbVariable.SQLString = "SELECT PropertyId FROM AW_RentTransaction WHERE TransactionId=@TransactionId"
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionID))
            objDB.FillData(TransactionDT, "Transaction", Database.SQLCommandType.NormalString)

            For Each ReadRow As Data.DataRow In TransactionDT.Rows
                PropertyId = ReadRow.Item("PropertyId").ToString
            Next

            Dim CurrentListType As Integer
            Dim CheckPropertyDT As New Data.DataTable
            'Check if Rent Transaction is at status 1
            objDB.dbVariable.SQLString = "SELECT ListType FROM AW_Property WHERE PropertyId=@PropertyId"
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
            objDB.FillData(CheckPropertyDT, "RentTrans", Database.SQLCommandType.NormalString)

            For Each ReadRow As Data.DataRow In CheckPropertyDT.Rows
                CurrentListType = ReadRow.Item("ListType")
            Next

            'begin relist
            Try
                objDB.InitDbTrans()

                Dim strAdditionalSQL As String
                If CurrentListType = 3 Then
                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, 1)   'Relist the RENT, maintain the SALE.
                    strAdditionalSQL = "RCreateDate=@RCreateDate,"
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, DBNull.Value)   'Edited by tanchinteong @26112012
                Else
                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, DBNull.Value)
                    strAdditionalSQL = "CreateDate=@CreateDate,UpdateDate=@UpdateDate,UpdateWho=@UpdateWho,RCreateDate=@RCreateDate,SCreateDate=@SCreateDate,AgentFeedback=@AgentFeedback, "
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, DBNull.Value)   'Edited by tanchinteong @26112012
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("AgentFeedback", Data.SqlDbType.Int, DBNull.Value)
                End If

                objDB.dbVariable.SQLString = "UPDATE AW_Property SET ListType=@ListType," & _ 
                                             "RRelistStatus=@RListStatus,RListerId=@RListerId,RTransactionId=@RTransactionId, " & strAdditionalSQL & _
                                             "RRAmt=@RRAmt,RRPSF=@RRPSF,RRAskAmt=@RRAskAmt,RRAskPSF=@RRAskPSF,RRCreateDate=@RRCreateDate,RRYes=@RRYes, " & _
                                             "RCAmt=@RCAmt,RCPSF=@RCPSF,RCAskAmt=@RCAskAmt,RCAskPSF=@RCAskPSF,RCCreateDate=@RCCreateDate,RCYes=@RCYes, " & _
                                             "RLAmt=@RLAmt,RLPSF=@RLPSF,RLAskAmt=@RLAskAmt,RLAskPSF=@RLAskPSF,RLCreateDate=@RLCreateDate,RLYes=@RLYes, " & _
                                             "RIAmt=@RIAmt,RIPSF=@RIPSF,RIAskAmt=@RIAskAmt,RIAskPSF=@RIAskPSF,RICreateDate=@RICreateDate,RIYes=@RIYes  " & _
                                             "WHERE PropertyId=@PropertyId"
                '"LandlordName=@LandlordName,LandlordMobile=@LandlordMobile,LandlordPhone=@LandlordPhone,LandlordFax=@LandlordFax,LandlordEmail=@LandlordEmail,LandlordAddress=@LandlordAddress, " & _
                objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyId))
                objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()

                objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET Status=4 WHERE TransactionId=@TransactionId"
                objDB.ClearParameter()
                objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionID))
                objDB.ExecuteQuery()

                InsertTrans_Old("", TransactionID, objDB)

                objDB.DbTransCommit()
                objDB.CloseConnection()

                divSuccessful.Visible = True
                lblMsgSuccessful.Text = "RENT has been RELISTED"
                SearchCompleteList()

            Catch ex As Exception
                objDB.DbTransRollback()
                objDB.CloseConnection()
                lblMsgError.Text = "There is an error with the following error message : " & ex.Message
                divError.Visible = True

            End Try
            Exit Sub
        End If




    End Sub

#Region " Order By Coding "

    Private Function SortType(ByVal strSortType As String) As String
        Dim strSort As String
        If Right(strSortType, 1) = "▼" Then
            strSort = "ASC"
        Else
            strSort = "DESC"
        End If
        Return strSort
    End Function

    Protected Sub lnkUnitNo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkUnitNo.Click
        If lnkUnitNo.Text = "Unit No▼" Then
            lnkUnitNo.Text = "Unit No▲"
        Else
            lnkUnitNo.Text = "Unit No▼"
        End If

        lblhidSortType.Text = "ORDER BY UnitNumber " & SortType(lnkUnitNo.Text) & ", Road " & SortType(lnkRoad.Text) & _
                        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)

        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkRoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkRoad.Click
        If lnkRoad.Text = "Road▼" Then
            lnkRoad.Text = "Road▲"
        Else
            lnkRoad.Text = "Road▼"
        End If

        lblhidSortType.Text = "ORDER BY Road " & SortType(lnkRoad.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkLocation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLocation.Click
        If lnkLocation.Text = "Location▼" Then
            lnkLocation.Text = "Location▲"
        Else
            lnkLocation.Text = "Location▼"
        End If

        lblhidSortType.Text = "ORDER BY Location " & SortType(lnkLocation.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", State " & SortType(lnkState.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkState_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkState.Click
        If lnkState.Text = "State▼" Then
            lnkState.Text = "State▲"
        Else
            lnkState.Text = "State▼"
        End If

        lblhidSortType.Text = "ORDER BY State " & SortType(lnkState.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkCountry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkCountry.Click
        If lnkCountry.Text = "Country▼" Then
            lnkCountry.Text = "Country▲"
        Else
            lnkCountry.Text = "Country▼"
        End If

        lblhidSortType.Text = "ORDER BY Country " & SortType(lnkCountry.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkProject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProject.Click
        If lnkProject.Text = "Project▼" Then
            lnkProject.Text = "Project▲"
        Else
            lnkProject.Text = "Project▼"
        End If

        lblhidSortType.Text = "ORDER BY Project " & SortType(lnkProject.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Country " & SortType(lnkCountry.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkType.Click
        If lnkType.Text = "Project Type▼" Then
            lnkType.Text = "Project Type▲"
        Else
            lnkType.Text = "Project Type▼"
        End If

        lblhidSortType.Text = "ORDER BY Type " & SortType(lnkType.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Country " & SortType(lnkCountry.Text) & _
                        ", Project " & SortType(lnkProject.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkGross.Click
        If lnkGross.Text = "Gross Amount▼" Then
            lnkGross.Text = "Gross Amount▲"
        Else
            lnkGross.Text = "Gross Amount▼"
        End If

        lblhidSortType.Text = "ORDER BY GrossAmount " & SortType(lnkGross.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Country " & SortType(lnkCountry.Text) & _
                        ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text)
        btnSearch_Click(sender, e)
    End Sub

#End Region

    Private Sub InsertTrans_Old(ByVal STransId As String, ByVal RTransId As String, ByVal objDB As Database)

        objDB.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objDB.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objDB.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblUserID.Text.Trim))
        objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
        objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 4)

        If STransId <> "" Then
            'insert
            objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_SaleTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, " & _
                                        "CloseFileRef, ListerId, ListDate, VendorType, VendorName1, VendorName2, VendorName3, VendorCompany, " & _
                                        "VendorNRIC1, VendorNRIC2, VendorNRIC3, VendorCompanyNo, VendorContactPerson, VendorAddress, VendorPhone, " & _
                                        "VendorMobile, VendorFax, VendorEmail, VendorReferral, VendorReferralName, VendorReferralNRIC, " & _
                                        "VendorReferralContact, VendorReferralStatus, VendorReferralAmount, VendorReferralAmtSum, AgencyFee, GST, GSTPaidBy, " & _
                                        "ListingFee, VendorSolicitorCompany, VendorSolicitorName, VendorSolicitorEmail, VendorSolicitorAddress, VendorSolicitorPhone, " & _
                                        "VendorSolicitorFax, PurchaserType, PurchaserName1, PurchaserName2, PurchaserName3, PurchaserCompany, PurchaserNRIC1, " & _
                                        "PurchaserNRIC2, PurchaserNRIC3, PurchaserCompanyNo, PurchaserContactPerson, PurchaserAddress, PurchaserPhone, " & _
                                        "PurchaserMobile, PurchaserFax, PurchaserEmail, PurchaserReferral, PurchaserReferralName, PurchaserReferralNRIC, " & _
                                        "PurchaserReferralContact, PurchaserReferralStatus, PurchaserReferralAmount, PurchaserReferralAmtSum, DisbursementFee, " & _
                                        "PurchaserSolicitorCompany, PurchaserSolicitorName, PurchaserSolicitorEmail, PurchaserSolicitorAddress, " & _
                                        "PurchaserSolicitorPhone, PurchaserSolicitorFax, TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, " & _
                                        "TransListType, TransactedPrice, Deposit, PaymentType, PaymentDate, Requisition, CreateDate, UpdateDate, UpdateWho, " & _
                                        "Status, TotalAgencyFee, ListerAmt, ReferralAmt, GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, " & _
                                        "SignCompleteDate, SNPDate, CollectDate, CollectAmt, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, " & _
                                        "UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, " & _
                                        "InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, VendorType, VendorName1, VendorName2, VendorName3, " & _
                                        "VendorCompany, VendorNRIC1, VendorNRIC2, VendorNRIC3, VendorCompanyNo, VendorContactPerson, VendorAddress, " & _
                                        "VendorPhone, VendorMobile, VendorFax, VendorEmail, VendorReferral, VendorReferralName, VendorReferralNRIC, " & _
                                        "VendorReferralContact, VendorReferralStatus, VendorReferralAmount, VendorReferralAmtSum, AgencyFee, GST, GSTPaidBy, " & _
                                        "ListingFee, VendorSolicitorCompany, VendorSolicitorName, VendorSolicitorEmail, VendorSolicitorAddress, VendorSolicitorPhone, " & _
                                        "VendorSolicitorFax, PurchaserType, PurchaserName1, PurchaserName2, PurchaserName3, PurchaserCompany, PurchaserNRIC1, " & _
                                        "PurchaserNRIC2, PurchaserNRIC3, PurchaserCompanyNo, PurchaserContactPerson, PurchaserAddress, PurchaserPhone, " & _
                                        "PurchaserMobile, PurchaserFax, PurchaserEmail, PurchaserReferral, PurchaserReferralName, PurchaserReferralNRIC, " & _
                                        "PurchaserReferralContact, PurchaserReferralStatus, PurchaserReferralAmount, PurchaserReferralAmtSum, DisbursementFee, " & _
                                        "PurchaserSolicitorCompany, PurchaserSolicitorName, PurchaserSolicitorEmail, PurchaserSolicitorAddress, " & _
                                        "PurchaserSolicitorPhone, PurchaserSolicitorFax, TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, " & _
                                        "TransListType, TransactedPrice, Deposit, PaymentType, PaymentDate, Requisition, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD, " & _
                                        "@Status, TotalAgencyFee, ListerAmt, ReferralAmt, GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, " & _
                                        "SignCompleteDate, SNPDate, CollectDate, CollectAmt, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, " & _
                                        "UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, UndoGST, UndoGSTPaidBy, UndoListerAmt FROM AW_SaleTransaction WHERE TransactionId = @STransId"
            objDB.AddParameter("STransId", Data.SqlDbType.UniqueIdentifier, New Guid(STransId))
            objDB.ExecuteQuery(False)
        End If
        If RTransId <> "" Then
            objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                     "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                     "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                     "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                     "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                     "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                     "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                     "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                     "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                     "TerminationClause, PremiseUse, CreateDate, UpdateDate, UpdateWho, Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                     "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                     "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                     "UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                     "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                     "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                     "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                     "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                     "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                     "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                     "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                     "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                     "TerminationClause, PremiseUse, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD, @Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                     "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                     "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                     "UndoGST, UndoGSTPaidBy, UndoListerAmt FROM AW_RentTransaction WHERE TransactionId=@RTransId"
            objDB.AddParameter("RTransId", Data.SqlDbType.UniqueIdentifier, New Guid(RTransId))
            objDB.ExecuteQuery(False)
        End If
    End Sub

   
End Class
